/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConfErrEditor.java
 *
 * Created on Feb 12, 2010, 1:55:48 PM
 */

package ch.epfl.dslab.conferrng.gui.arugula;

import ch.epfl.dslab.conferrng.arugula.Operator;
import ch.epfl.dslab.conferrng.engine.FaultInjectionPlan;
import ch.epfl.dslab.conferrng.engine.Parameter;
import ch.epfl.dslab.conferrng.gui.ParameterCellEditor;
import java.awt.Color;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;

/**
 *
 * @author slv
 */
public class ConfErrEditor extends javax.swing.JPanel {

    private FaultInjectionPlan plan;
    /** Creates new form ConfErrEditor */
    public ConfErrEditor(Operator op) {
        plan = op.getPlan();
        setParameters(op.getParameters());
        initComponents();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jScrollPane1 = new javax.swing.JScrollPane();
        paramTable = new javax.swing.JTable();

        setBackground(new Color(0xFFFFFFFF, true));
        setPreferredSize(new java.awt.Dimension(500, 125));
        setLayout(new java.awt.BorderLayout());

        paramTable.setModel(new  javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Type", "Value"
            }));

            org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${parameters}");
            org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, this, eLProperty, paramTable);
            org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${name}"));
            columnBinding.setColumnName("Name");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${type}"));
            columnBinding.setColumnName("Type");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${value}"));
            columnBinding.setColumnName("Value");
            columnBinding.setColumnClass(String.class);
            bindingGroup.addBinding(jTableBinding);
            jTableBinding.bind();
            jScrollPane1.setViewportView(paramTable);
            paramTable.getColumnModel().getColumn(0).setResizable(false);
            paramTable.getColumnModel().getColumn(1).setResizable(false);
            paramTable.getColumnModel().getColumn(2).setCellEditor(new ParameterCellEditor(plan));

            add(jScrollPane1, java.awt.BorderLayout.CENTER);

            bindingGroup.bind();
        }// </editor-fold>//GEN-END:initComponents
    protected List<Parameter> parameters;
    public static final String PROP_PARAMETERS = "parameters";

    /**
     * Get the value of parameters
     *
     * @return the value of parameters
     */
    public List<Parameter> getParameters() {
        return parameters;
    }

    /**
     * Set the value of parameters
     *
     * @param parameters new value of parameters
     */
    public void setParameters(List<Parameter> parameters) {
        List oldParameters = this.parameters;
        this.parameters = parameters;
        propertyChangeSupport.firePropertyChange(PROP_PARAMETERS, oldParameters, parameters);
    }
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable paramTable;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
